import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        int generateNumber;
        int userNumber;
        int maxTimes = 3;
        int i = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.printf("欢迎来到[猜数字游戏]，请输入一个[0-100]之间的整数，你有%d次机会尝试。\n", maxTimes);
        
        do {
            generateNumber = (int) (Math.random() * 100);
            for (i = 0; i < maxTimes; i++) {
                System.out.print("请输入你猜的数字: ");
                userNumber = scanner.nextInt();
                if (userNumber == generateNumber) {
                    System.out.println("恭喜你，猜中啦！");
                    break;
                } else if (userNumber > generateNumber) {
                    System.out.println("很遗憾，猜大了！");
                } else {
                    System.out.println("很遗憾，猜小了！");
                }
            }
            if (i == maxTimes) {
                System.out.println("尝试次数太多，本轮游戏结束，正确答案是: " + generateNumber);
            }
            System.out.print("是否还要再来一轮？[Y/N]: ");
            String yn = scanner.next();
            if (!yn.equalsIgnoreCase("Y")) {
                break;
            }
        } while (true);
        
        System.out.println("再见!");
        scanner.close();
    }
}